﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Add_Class
{
    public partial class Form1 : Form
    {
        List<SinhVien> lsv;//Cai nay de listBox
        List<SinhVien> lsv_dgv;//cai nay de luu vao DataGrdView
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            lsv = new List<SinhVien>();
            lsv_dgv = new List<SinhVien>();
            lsv.Add(new SinhVien("01706","Mai Phuong Thuy","Led","Ha noi"));
            lsv.Add(new SinhVien("01898","Phuong Trinh","unknown","TP HO cHI Minh"));
            lsv.Add(new SinhVien("01889", "Dep trai", "good boy", "Ha noi"));
            lb_sv.DataSource = lsv;
            lb_sv.DisplayMember = "Ma";// Item se hien thi tren list box
            lb_sv.ValueMember = "Ma";//gia tri khi lay, co the lay item khac nhu ten hay gioi tinh
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < lsv.Count; i++)
                if (lsv[i].Ma.Equals(lb_sv.SelectedValue))
                {
                    lsv_dgv.Add(lsv[i]);
                    lsv.RemoveAt(i);
                }
            this.resetData();
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = lsv_dgv;
        }
        private void resetData()
        {
            lb_sv.DataSource = null;
            lb_sv.DataSource = lsv;
            lb_sv.DisplayMember = "Ma";// Item se hien thi tren list box
            lb_sv.ValueMember = "Ma";//gia tri khi lay, co the lay item khac nhu ten hay gioi tinh
        }
    }
}
